#!/bin/bash


if [ -z $1 ];then
   echo "Usage: $0 Command"
   exit 1
fi


HOST_LIST_FILE="/root/ldz/demo/host_list.txt"

COMMAND=$@

for IP in $(awk '/^[^#]/{print $1}' $HOST_LIST_FILE);do
    USER=$(awk -v I=$IP 'I==$1{print $2}' $HOST_LIST_FILE)
    PASS=$(awk -v I=$IP 'I==$1{print $3}' $HOST_LIST_FILE)
    PORT=$(awk -v I=$IP 'I==$1{print $4}' $HOST_LIST_FILE)
    echo "-----------$IP----------"
    sshpass -p "$PASS" ssh -p "$PORT" "$USER@$IP" "$COMMAND"
done
